package com.chen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.bean.Dish;
import com.chen.common.R;
import com.chen.dto.DishDto;
import com.chen.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/dish")
@RestController
public class DishController {
    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     * @param dishDto
     * @return
     */
    @PostMapping
    public R<String> addDish(@RequestBody DishDto dishDto){
        return dishService.addDish(dishDto);
    }

    /**
     * 菜品分页展示
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public R<Page<DishDto>> dishPage(Integer page, Integer pageSize, String name){
        return dishService.dishPage(page,pageSize,name);
    }

    /**
     * 回显要修改的菜品信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<DishDto> echoDish(@PathVariable Long id){
        return dishService.echoDish(id);
    }

    /**
     * 修改菜品信息
     * @param dishDto
     * @return
     */
    @PutMapping
    public R<String> updateDish(@RequestBody DishDto dishDto){
        return dishService.updateDish(dishDto);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public R<String> deleteDish(@RequestParam Long[] ids){
        return dishService.deleteDish(ids);
    }

    /**
     * 修改状态
     * @param status
     * @param ids
     * @return
     */
    @PostMapping("/status/{status}")
    public R<String> updateStatus(@PathVariable Integer status,@RequestParam Long[] ids){
        return dishService.updateStatus(status,ids);
    }

    /**
     * 按菜品分类id  和菜品名字查询
     * @param dish
     * @return
     */
    @GetMapping("/list")
    public R<List<Dish>> findByCategoryIdOrName(Dish dish){
        return dishService.findByCategoryIdOrName(dish);
    }

}
